package com.yun.algorithmproblem.leetcode;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Leetcode1 {

    public int[] twoSum(int[] nums, int target) {
        Map<Integer,Integer> m=new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if(!m.containsKey(nums[i])){
                m.put(target-nums[i],i);
            }else {
                return new int[]{m.get(nums[i]),i};
            }
        }
        return null;
    }

    public static void main(String[] args) {
        int[] a={2,7,11,15};
        int[] b=new Leetcode1().twoSum(a,9);
        System.out.println(Arrays.toString(b));
    }
}
